package la.bbs558.util;

import cn.hutool.crypto.SecureUtil;
import cn.hutool.crypto.asymmetric.KeyType;
import cn.hutool.crypto.asymmetric.RSA;

import java.nio.charset.StandardCharsets;

/**
 * @Classname RSAUtils
 * @Description TODO
 * @Date 2023/12/5 14:42
 * @Created by weihanmin
 */
public class RSAUtils {
    public static RSA rsa = SecureUtil.rsa();


    public static byte[] encrypt(byte[] data){
        return rsa.encrypt(data, KeyType.PublicKey);
    }

    public static byte[] decrypt(byte[] data){
        return rsa.decrypt(data,KeyType.PrivateKey);
    }

    public static void main(String[] args) {
        byte[] encrypt = encrypt("qaz123".getBytes(StandardCharsets.UTF_8));
        byte[] decrypt = decrypt(encrypt);
        System.out.println("encrypt = " + new String(encrypt,StandardCharsets.UTF_8));
        System.out.println("decrypt = " + new String(decrypt));
    }
}
